import os
import sys
import wdconfig

if os.getenv('RTT_ROOT'):
    RTT_ROOT = os.getenv('RTT_ROOT')
else:
    RTT_ROOT = os.path.normpath(os.getcwd() + '/..')

sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *

TARGET = 'VideoTransmit.' + wdconfig.TARGET_EXT

env = Environment(tools = ['mingw'],
	AS = wdconfig.AS, ASFLAGS = wdconfig.AFLAGS,
	CC = wdconfig.CC, CCFLAGS = wdconfig.CFLAGS,
	AR = wdconfig.AR, ARFLAGS = '-rc',
	LINK = wdconfig.LINK, LINKFLAGS = wdconfig.LFLAGS)
env.PrependENVPath('PATH', wdconfig.EXEC_PATH)

Export('RTT_ROOT')
Export('wdconfig')

# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT)

# STM32 firmware library building script
objs = SConscript( RTT_ROOT +'/USER/SConscript' , variant_dir='build/USER' , duplicate=0)

if GetDepend('DRIVERS_LOAD'):
	objs = objs + SConscript( RTT_ROOT +'/HARDWARE/SConscript' , variant_dir='build/HARDWARE' , duplicate=0)

objs = objs + SConscript( RTT_ROOT +'/FWLIB/SConscript', variant_dir='build/FWLIB', duplicate=0)	
objs = objs + SConscript( RTT_ROOT +'/SYSTEM/SConscript' , variant_dir='build/SYSTEM' , duplicate=0)
objs = objs + SConscript( RTT_ROOT +'/UCOSII/SConscript' , variant_dir='build/UCOSII' , duplicate=0)
objs = objs + SConscript( RTT_ROOT +'/MALLOC/SConscript' , variant_dir='build/MALLOC' , duplicate=0)
objs = objs + SConscript( RTT_ROOT +'/Fatfs/SConscript' , variant_dir='build/Fatfs' , duplicate=0)

#if GetDepend('RT_USING_RTGUI'):
#    objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0)

# build program 
env.Program(TARGET, objs)

# end building 
EndBuilding(TARGET)
